<template>
	<view>
		<view class="main">
			<view class="title">智慧城市</view>
			<u-form :model="form" label-width="160">
				<u-form-item label="账号">
					<u-input v-model="form.username"></u-input>
				</u-form-item>
				<u-form-item label="密码">
					<u-input type="password" v-model="form.password"></u-input>
				</u-form-item>
			</u-form>
			<navigator url="/pages/register/register" class="register">
				<text>没有账号？点我注册登入</text>
			</navigator>
			<button @click="submit">登入</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					username: '',
					password: ''
				}
			};
		},
		methods: {
			submit(){
				this.$request({
					url: '/prod-api/api/login',
					method: 'POST',
					data: {
						...this.form
					}
				}).then(res => {
					if(res.code === 200){
						uni.setStorageSync('token', res.token)
						uni.showToast({
							title:'登入成功'
						})
						uni.switchTab({
							url:'/pages/index/index'
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon: 'error'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	view{
	.main{
		padding: 20rpx;
		.title{
			color: #2979ff;
			font-size: 45rpx;
			text-align: center;
			margin-top: 20rpx;
			font-weight: bold;
		}
		u-form{
			margin-top: 20rpx;
		}
		.register{
			display: flex;
			flex-direction: row;
			justify-content: end;
			color: #2979ff;
			font-size: 22rpx;
			margin-top: 10rpx;
		}
		button{
			width: 240rpx;
			height: 80rpx;
			text-align: center;
			font-size: 28rpx;
			background-color: #2979ff;
			color: white;
			margin-top: 50rpx;
		}
	}	
	}
</style>
